package com.qiangesoft.cloud.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {

//    private static final String PAY_URL = "http://localhost:8002/";
    private static final String PAY_URL = "http://provider-payment/";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/add")
    public Map<String, Object> add(String name) {
        Map<String, Object> map = new HashMap<>(4);

        ResponseEntity<String> entity = restTemplate.getForEntity(PAY_URL + "payment/add?name=" + name, String.class);
        map.put("payId", entity.getBody());
        map.put("orderId", UUID.randomUUID().toString().replace("-", ""));

        System.out.println(name + "下单成功");
        return map;
    }
}
